<?php
namespace Home\Controller;
class YuyueController extends LoginController{
    function index(){
        $this->getip();
        $this->display();
    }
    function add(){
       if (!IS_POST) {
            $this->ajaxReturn(['status' => 0, 'msg' => '非法请求']);
        }
        
        $subscribe_model  = M("Liangfang");
        $_POST["addtime"] = time();
        $_POST["ip"]      = get_client_ip();

        $rules = [
//            ['name', 'require', '请输入您的姓名！'],
            ['huxing', 'require', '请选择您的房屋户型！'],
            ['city', 'require', '请选择您的所在城市！'],
            ['mobile', '/^\d{11}$/', '请输入正确的手机号！', 1, 'regex', 3],
            ['area', 'require', '请输入您的房屋面积！'],
        ];
        if (!$subscribe_model->validate($rules)->create($_POST)) {
            $this->ajaxReturn(['status' => 0, 'msg' => $subscribe_model->getError()]);
        };

        if (!$subscribe_model->add()) {
            $this->ajaxReturn(['status' => 0, 'msg' => '添加失败，请重新填写！']);
        }

        $this->ajaxReturn(['status' => 1, 'msg' => '添加成功']);
    }
}
